<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang = "en">

<head>

<link rel="shortcut icon" href="http://algs4.cs.princeton.edu/favicon.ico">
<link rel="stylesheet"    href="http://algs4.cs.princeton.edu/java.css" type="text/css">

<title>GrahamScan.java</title>

<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<meta NAME="AUTHOR" CONTENT="Robert Sedgewick and Kevin Wayne">
<meta NAME="DESCRIPTION" CONTENT="GrahamScan code in Java">
<meta NAME="TITLE" CONTENT="GrahamScan code in Java">
<meta NAME="KEYWORDS" CONTENT="GrahamScan,java,programming,computer science,algorithm,data structure,program,code">
<meta NAME="ROBOTS" CONTENT="INDEX,FOLLOW">

</head>


<body>
<center><h1>GrahamScan.java</h1></center><p><br>

Below is the syntax highlighted version of <a href = "GrahamScan.java">GrahamScan.java</a>.
<p><br>

<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span class="comment">/******************************************************************************</span>
<span class="comment"> *  Compilation:  javac GrahamaScan.java</span>
<span class="comment"> *  Execution:    java GrahamScan &lt; input.txt</span>
<span class="comment"> *  Dependencies: Point2D.java</span>
<span class="comment"> * </span>
<span class="comment"> *  Create points from standard input and compute the convex hull using</span>
<span class="comment"> *  Graham scan algorithm.</span>
<span class="comment"> *</span>
<span class="comment"> *  May be floating-point issues if x- and y-coordinates are not integers.</span>
<span class="comment"> *</span>
<span class="comment"> ******************************************************************************/</span>

<span class="preproc">package</span><span class="normal"> edu</span><span class="symbol">.</span><span class="normal">princeton</span><span class="symbol">.</span><span class="normal">cs</span><span class="symbol">.</span><span class="normal">algs4</span><span class="symbol">;</span>

<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">Arrays</span><span class="symbol">;</span>


<span class="comment">/**</span>
<span class="comment"> *  The </span><span class="keyword">&lt;tt&gt;</span><span class="comment">GrahamScan</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> data type provides methods for computing the </span>
<span class="comment"> *  convex hull of a set of </span><span class="keyword">&lt;em&gt;</span><span class="comment">N</span><span class="keyword">&lt;/em&gt;</span><span class="comment"> points in the plane.</span>
<span class="comment"> *  </span><span class="keyword">&lt;p&gt;</span>
<span class="comment"> *  The implementation uses the Graham-Scan convex hull algorithm.</span>
<span class="comment"> *  It runs in O(</span><span class="keyword">&lt;em&gt;</span><span class="comment">N</span><span class="keyword">&lt;/em&gt;</span><span class="comment"> log </span><span class="keyword">&lt;em&gt;</span><span class="comment">N</span><span class="keyword">&lt;/em&gt;</span><span class="comment">) time in the worst case</span>
<span class="comment"> *  and uses O(</span><span class="keyword">&lt;em&gt;</span><span class="comment">N</span><span class="keyword">&lt;/em&gt;</span><span class="comment">) extra memory.</span>
<span class="comment"> *  </span><span class="keyword">&lt;p&gt;</span>
<span class="comment"> *  For additional documentation, see </span><span class="keyword">&lt;a</span><span class="normal"> </span><span class="type">href</span><span class="symbol">=</span><span class="string">"http://algs4.cs.princeton.edu/99scientific"</span><span class="keyword">&gt;</span><span class="comment">Section 9.9</span><span class="keyword">&lt;/a&gt;</span><span class="comment"> of</span>
<span class="comment"> *  </span><span class="keyword">&lt;i&gt;</span><span class="comment">Algorithms, 4th Edition</span><span class="keyword">&lt;/i&gt;</span><span class="comment"> by Robert Sedgewick and Kevin Wayne.</span>
<span class="comment"> *</span>
<span class="comment"> *  </span><span class="type">@author</span><span class="comment"> Robert Sedgewick</span>
<span class="comment"> *  </span><span class="type">@author</span><span class="comment"> Kevin Wayne</span>
<span class="comment"> */</span>
<span class="keyword">public</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">GrahamScan</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">private</span><span class="normal"> </span><span class="usertype">Stack&lt;Point2D&gt;</span><span class="normal"> hull </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> Stack</span><span class="symbol">&lt;</span><span class="normal">Point2D</span><span class="symbol">&gt;();</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Computes the convex hull of the specified array of points.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  pts the array of points</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">points</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> or if any</span>
<span class="comment">     *         entry in </span><span class="keyword">&lt;tt&gt;</span><span class="comment">points[]</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="function">GrahamScan</span><span class="symbol">(</span><span class="normal">Point2D</span><span class="symbol">[]</span><span class="normal"> pts</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>

<span class="normal">        </span><span class="comment">// defensive copy</span>
<span class="normal">        </span><span class="type">int</span><span class="normal"> N </span><span class="symbol">=</span><span class="normal"> pts</span><span class="symbol">.</span><span class="normal">length</span><span class="symbol">;</span>
<span class="normal">        Point2D</span><span class="symbol">[]</span><span class="normal"> points </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> Point2D</span><span class="symbol">[</span><span class="normal">N</span><span class="symbol">];</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="type">int</span><span class="normal"> i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol">&lt;</span><span class="normal"> N</span><span class="symbol">;</span><span class="normal"> i</span><span class="symbol">++)</span>
<span class="normal">            points</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> pts</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">];</span>

<span class="normal">        </span><span class="comment">// preprocess so that points[0] has lowest y-coordinate; break ties by x-coordinate</span>
<span class="normal">        </span><span class="comment">// points[0] is an extreme point of the convex hull</span>
<span class="normal">        </span><span class="comment">// (alternatively, could do easily in linear time)</span>
<span class="normal">        Arrays</span><span class="symbol">.</span><span class="function">sort</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">);</span>

<span class="normal">        </span><span class="comment">// sort by polar angle with respect to base point points[0],</span>
<span class="normal">        </span><span class="comment">// breaking ties by distance to points[0]</span>
<span class="normal">        Arrays</span><span class="symbol">.</span><span class="function">sort</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1</span><span class="symbol">,</span><span class="normal"> N</span><span class="symbol">,</span><span class="normal"> points</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">].</span><span class="function">polarOrder</span><span class="symbol">());</span>

<span class="normal">        hull</span><span class="symbol">.</span><span class="function">push</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">]);</span><span class="normal">       </span><span class="comment">// p[0] is first extreme point</span>

<span class="normal">        </span><span class="comment">// find index k1 of first point not equal to points[0]</span>
<span class="normal">        </span><span class="type">int</span><span class="normal"> k1</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">k1 </span><span class="symbol">=</span><span class="normal"> </span><span class="number">1</span><span class="symbol">;</span><span class="normal"> k1 </span><span class="symbol">&lt;</span><span class="normal"> N</span><span class="symbol">;</span><span class="normal"> k1</span><span class="symbol">++)</span>
<span class="normal">            </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(!</span><span class="normal">points</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">].</span><span class="function">equals</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">[</span><span class="normal">k1</span><span class="symbol">]))</span><span class="normal"> </span><span class="keyword">break</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">k1 </span><span class="symbol">==</span><span class="normal"> N</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="symbol">;</span><span class="normal">        </span><span class="comment">// all points equal</span>

<span class="normal">        </span><span class="comment">// find index k2 of first point not collinear with points[0] and points[k1]</span>
<span class="normal">        </span><span class="type">int</span><span class="normal"> k2</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">k2 </span><span class="symbol">=</span><span class="normal"> k1 </span><span class="symbol">+</span><span class="normal"> </span><span class="number">1</span><span class="symbol">;</span><span class="normal"> k2 </span><span class="symbol">&lt;</span><span class="normal"> N</span><span class="symbol">;</span><span class="normal"> k2</span><span class="symbol">++)</span>
<span class="normal">            </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">Point2D</span><span class="symbol">.</span><span class="function">ccw</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">[</span><span class="number">0</span><span class="symbol">],</span><span class="normal"> points</span><span class="symbol">[</span><span class="normal">k1</span><span class="symbol">],</span><span class="normal"> points</span><span class="symbol">[</span><span class="normal">k2</span><span class="symbol">])</span><span class="normal"> </span><span class="symbol">!=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">break</span><span class="symbol">;</span>
<span class="normal">        hull</span><span class="symbol">.</span><span class="function">push</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">[</span><span class="normal">k2</span><span class="symbol">-</span><span class="number">1</span><span class="symbol">]);</span><span class="normal">    </span><span class="comment">// points[k2-1] is second extreme point</span>

<span class="normal">        </span><span class="comment">// Graham scan; note that points[N-1] is extreme point different from points[0]</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="type">int</span><span class="normal"> i </span><span class="symbol">=</span><span class="normal"> k2</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol">&lt;</span><span class="normal"> N</span><span class="symbol">;</span><span class="normal"> i</span><span class="symbol">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            </span><span class="usertype">Point2D</span><span class="normal"> top </span><span class="symbol">=</span><span class="normal"> hull</span><span class="symbol">.</span><span class="function">pop</span><span class="symbol">();</span>
<span class="normal">            </span><span class="keyword">while</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">Point2D</span><span class="symbol">.</span><span class="function">ccw</span><span class="symbol">(</span><span class="normal">hull</span><span class="symbol">.</span><span class="function">peek</span><span class="symbol">(),</span><span class="normal"> top</span><span class="symbol">,</span><span class="normal"> points</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">])</span><span class="normal"> </span><span class="symbol">&lt;=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">                top </span><span class="symbol">=</span><span class="normal"> hull</span><span class="symbol">.</span><span class="function">pop</span><span class="symbol">();</span>
<span class="normal">            </span><span class="cbracket">}</span>
<span class="normal">            hull</span><span class="symbol">.</span><span class="function">push</span><span class="symbol">(</span><span class="normal">top</span><span class="symbol">);</span>
<span class="normal">            hull</span><span class="symbol">.</span><span class="function">push</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">]);</span>
<span class="normal">        </span><span class="cbracket">}</span>

<span class="normal">        </span><span class="keyword">assert</span><span class="normal"> </span><span class="function">isConvex</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the extreme points on the convex hull in counterclockwise order.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the extreme points on the convex hull in counterclockwise order</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Iterable&lt;Point2D&gt;</span><span class="normal"> </span><span class="function">hull</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="usertype">Stack&lt;Point2D&gt;</span><span class="normal"> s </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> Stack</span><span class="symbol">&lt;</span><span class="normal">Point2D</span><span class="symbol">&gt;();</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Point2D</span><span class="normal"> p </span><span class="symbol">:</span><span class="normal"> hull</span><span class="symbol">)</span><span class="normal"> s</span><span class="symbol">.</span><span class="function">push</span><span class="symbol">(</span><span class="normal">p</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> s</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">// check that boundary of hull is strictly convex</span>
<span class="normal">    </span><span class="keyword">private</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">isConvex</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="type">int</span><span class="normal"> N </span><span class="symbol">=</span><span class="normal"> hull</span><span class="symbol">.</span><span class="function">size</span><span class="symbol">();</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">N </span><span class="symbol">&lt;=</span><span class="normal"> </span><span class="number">2</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">true</span><span class="symbol">;</span>

<span class="normal">        Point2D</span><span class="symbol">[]</span><span class="normal"> points </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> Point2D</span><span class="symbol">[</span><span class="normal">N</span><span class="symbol">];</span>
<span class="normal">        </span><span class="type">int</span><span class="normal"> n </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Point2D</span><span class="normal"> p </span><span class="symbol">:</span><span class="normal"> </span><span class="function">hull</span><span class="symbol">())</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            points</span><span class="symbol">[</span><span class="normal">n</span><span class="symbol">++]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> p</span><span class="symbol">;</span>
<span class="normal">        </span><span class="cbracket">}</span>

<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="type">int</span><span class="normal"> i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol">&lt;</span><span class="normal"> N</span><span class="symbol">;</span><span class="normal"> i</span><span class="symbol">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">Point2D</span><span class="symbol">.</span><span class="function">ccw</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">],</span><span class="normal"> points</span><span class="symbol">[(</span><span class="normal">i</span><span class="symbol">+</span><span class="number">1</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">%</span><span class="normal"> N</span><span class="symbol">],</span><span class="normal"> points</span><span class="symbol">[(</span><span class="normal">i</span><span class="symbol">+</span><span class="number">2</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">%</span><span class="normal"> N</span><span class="symbol">])</span><span class="normal"> </span><span class="symbol">&lt;=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">                </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">;</span>
<span class="normal">            </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">true</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">   </span><span class="comment">/**</span>
<span class="comment">     * Unit tests the </span><span class="keyword">&lt;tt&gt;</span><span class="comment">ClosestPair</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> data type.</span>
<span class="comment">     * Reads in an integer </span><span class="keyword">&lt;tt&gt;</span><span class="comment">N</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> and </span><span class="keyword">&lt;tt&gt;</span><span class="comment">N</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> points (specified by</span>
<span class="comment">     * their </span><span class="keyword">&lt;em&gt;</span><span class="comment">x</span><span class="keyword">&lt;/em&gt;</span><span class="comment">- and </span><span class="keyword">&lt;em&gt;</span><span class="comment">y</span><span class="keyword">&lt;/em&gt;</span><span class="comment">-coordinates) from standard input;</span>
<span class="comment">     * computes their convex hull; and prints out the points on the</span>
<span class="comment">     * convex hull to standard output.</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="keyword">static</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">main</span><span class="symbol">(</span><span class="normal">String</span><span class="symbol">[]</span><span class="normal"> args</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="type">int</span><span class="normal"> N </span><span class="symbol">=</span><span class="normal"> StdIn</span><span class="symbol">.</span><span class="function">readInt</span><span class="symbol">();</span>
<span class="normal">        Point2D</span><span class="symbol">[]</span><span class="normal"> points </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> Point2D</span><span class="symbol">[</span><span class="normal">N</span><span class="symbol">];</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="type">int</span><span class="normal"> i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol">&lt;</span><span class="normal"> N</span><span class="symbol">;</span><span class="normal"> i</span><span class="symbol">++)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            </span><span class="type">int</span><span class="normal"> x </span><span class="symbol">=</span><span class="normal"> StdIn</span><span class="symbol">.</span><span class="function">readInt</span><span class="symbol">();</span>
<span class="normal">            </span><span class="type">int</span><span class="normal"> y </span><span class="symbol">=</span><span class="normal"> StdIn</span><span class="symbol">.</span><span class="function">readInt</span><span class="symbol">();</span>
<span class="normal">            points</span><span class="symbol">[</span><span class="normal">i</span><span class="symbol">]</span><span class="normal"> </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">Point2D</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">,</span><span class="normal"> y</span><span class="symbol">);</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="usertype">GrahamScan</span><span class="normal"> graham </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">GrahamScan</span><span class="symbol">(</span><span class="normal">points</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Point2D</span><span class="normal"> p </span><span class="symbol">:</span><span class="normal"> graham</span><span class="symbol">.</span><span class="function">hull</span><span class="symbol">())</span>
<span class="normal">            StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="normal">p</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="cbracket">}</span>

<span class="comment">/******************************************************************************</span>
<span class="comment"> *  Copyright 2002-2015, Robert Sedgewick and Kevin Wayne.</span>
<span class="comment"> *</span>
<span class="comment"> *  This file is part of algs4.jar, which accompanies the textbook</span>
<span class="comment"> *</span>
<span class="comment"> *      Algorithms, 4th edition by Robert Sedgewick and Kevin Wayne,</span>
<span class="comment"> *      Addison-Wesley Professional, 2011, ISBN 0-321-57351-X.</span>
<span class="comment"> *      </span><span class="url">http://algs4.cs.princeton.edu</span>
<span class="comment"> *</span>
<span class="comment"> *</span>
<span class="comment"> *  algs4.jar is free software: you can redistribute it and/or modify</span>
<span class="comment"> *  it under the terms of the GNU General Public License as published by</span>
<span class="comment"> *  the Free Software Foundation, either version 3 of the License, or</span>
<span class="comment"> *  (at your option) any later version.</span>
<span class="comment"> *</span>
<span class="comment"> *  algs4.jar is distributed in the hope that it will be useful,</span>
<span class="comment"> *  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> *  GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> *  You should have received a copy of the GNU General Public License</span>
<span class="comment"> *  along with algs4.jar.  If not, see </span><span class="url">http://www.gnu.org/licenses.</span>
<span class="comment"> ******************************************************************************/</span>
</tt></pre>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-10811519-2");
pageTracker._trackPageview();
} catch(err) {}</script>

</body>

<p><br><address><small>
Last updated: Mon Mar 21 10:51:08 EDT 2016.
</small></address>

</html>
